﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SomeRandomGame.Interfaces;

namespace SomeRandomGame.Particles
{
    public class ShipMotorParticle : IParticle
    {
        private float _alphaValue;
        public Texture2D Texture { get; set; }
        public Vector2 Position { get; set; }
        public Vector2 Velocity { get; set; }
        public float Angle { get; set; }
        public float AngularVelocity { get; set; }
        public Color Color { get; set; }
        public float Size { get; set; }
        public int Ttl { get; set; }

        public ShipMotorParticle(Texture2D texture, Vector2 position, Vector2 velocity,
            float angle, float angularVelocity, Color color, float size, int ttl)
        {
            Texture = texture;
            Position = position;
            Velocity = velocity;
            Angle = angle;
            AngularVelocity = angularVelocity;
            Color = color;
            Size = size;
            Ttl = ttl;
            _alphaValue = 1;
        }

        public void Initialize(IGameManager gameManager)
        {
        }

        public void Update(IGameManager gameManager)
        {
            Ttl--;
            _alphaValue = (float)((Ttl - 20) / 0.4) / 100 + 0.2f;
            Color = Color * _alphaValue;
            Position += Velocity;
            Angle += AngularVelocity;
        }

        public void Draw(SpriteBatch spriteBatch, IGameManager gameManager, GameTime gameTime)
        {
            Rectangle sourceRectangle = new Rectangle(0, 0, Texture.Width, Texture.Height);
            Vector2 origin = new Vector2(Texture.Width / 2, Texture.Height / 2);

            spriteBatch.Draw(Texture, Position, sourceRectangle, Color,
                Angle, origin, Size, SpriteEffects.None, 0f);
        }
    }
}
